package com.huang.controller;

import com.huang.dao.AdoptionMapper;
import com.huang.entity.Adoption;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@ResponseBody
public class AdoptionController {
    @Autowired
    AdoptionMapper adoptionMapper;

    @PostMapping("/insert/adoption")
    public String insertAdoption(@RequestBody Adoption adoption){
        int i = adoptionMapper.insertAdoption(adoption);
        if (i>0){
            return "success";
        }else {
            return "error";
        }
    }
    @DeleteMapping("/delete/adoption/{id}")
    public String deleteAdoption(@PathVariable("id") Integer id){
        int i = adoptionMapper.deleteById(id);
        if (i>0){
            return "success";
        }else {
            return "error";
        }
    }
    @GetMapping("/querry/alladoption/{userId}")
    public List<Adoption> querryAllAdoption(@PathVariable("userId")Integer userId){
        List<Adoption> adoptions = adoptionMapper.querryAdoptionByUserId(userId);
        return adoptions;
    }
}
